package com.imooc.set;

import java.util.Objects;

public class Cat {
    private String name;
    private int month;
    private String species;


    public Cat(String name, int month, String species) {
        super();//作用?
        this.name = name;
        this.month = month;
        this.species = species;
    }


    public String getName() {
        return name;
    }

    public int getMonth() {
        return month;
    }

    public String getSpecies() {
        return species;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public void setSpecies(String species) {
        this.species = species;
    }

    //可以快捷生成(右键generate)
    @Override
    public String toString() {
        return "Cat{" +
                "name='" + name + '\'' +
                ", month=" + month +
                ", species='" + species + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {

        if (this == o) //this为当前累的对象，o为传入对象，判断对象是否相等，相等时不用比较属性
        return true;
        if (o == null || getClass() != o.getClass()) //反射，若不是同一个类的返回false
        return false;

        Cat cat = (Cat) o;//若o为cat类的对象强制转换为cat类的对象
        return month == cat.month &&
                name.equals(cat.name) &&
                species.equals(cat.species);//得到两个cat对象后判断两个cat对象的属性是否相等
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, month, species);
    }
}

